<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>ShoppingShow</title>

    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le styles -->
   <link href="<?php echo base_url();?>common/bootstrap.css" rel="stylesheet">
   <script type="text/javascript" src="<?php echo base_url();?>common/jquery-1.3.min.js" ></script>
	<style type="text/css">
	      body {
	        padding-top: 60px;
	      }
	     
	     html, body {
        background-color: #FFFAF0;
     	 }
      	body {
        	padding-top: 50px; /* 40px to make the container go all the way to the bottom of the topbar */
     	 }
      	.container > footer p {
        text-align: center; /* center align it with the container */
     	 }
      	.container {
         width: 1100px; /* downsize our container to make the content feel a bit tighter and more cohesive. NOTE: this removes two full columns from the grid, meaning you only go to 14 columns and not 16. */
     	 }
     	 .article{
     	 	border-width:1px;
     	 	border:#FFE4E1;
     	 	
     	 	padding-top:3px; 
			padding-bottom:5%;
     	 	
     	 }
     	 .article a img.thumbnail{
			max-width:300px;
			max-height:500px;
	
			}

			.article p{
				text-align:right;
			}
			
			.img{
				text-align:center;
			}
	</style>
<script type="text/javascript">

function checkInput(){

	var url = document.getElementById("comment").value;

	if(LTrim(url).length == 0)
	{

		alert("Comment can not be empty!");
		
		$("#comment").focus();
		return false;
	}
	return true;
}

function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str); 
	if (whitespace.indexOf(s.charAt(0)) != -1){
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
	j++;
	}
	s = s.substring(j,i);
}
return s;
}

</script>
	</head>
<body>
   <div class="topbar">
      <div class="fill">
        <div class="container" >
          <a class="brand" href="<?php echo base_url();?>">ShoppingShow</a>
          <ul class="nav">
          		<?php if(isset($user_id)){?>
	          		<li><a href="#"><?php echo $user_id.", welcome!";?></a></li>
	             	<li><a href="<?php echo site_url("items/myPageShow");?>">MyPage</a></li>
	             	<li><a href="<?php echo site_url("users/logout");?>">Logout</a></li>
             	<?php }?>
             	<?php if($pastUrl=="0"){?>
             		<li><a href="<?php echo site_url("items/mainShow");?>">Back</a></li>
             	<?php }else{?>
             		<li><a href="<?php echo site_url("items/myPageShow");?>">Back</a></li>
            	 <?php }?>
          </ul>
          
           <?php if(!isset($user_id)){?>
            <form action="<?php echo site_url("users/login");?>" method="post">
	            <input class="input-small" type="text" name="name" placeholder="Username">
	            <input class="input-small" type="password" name="psd" placeholder="Password">
	            <button class="btn" type="submit">Sign in</button>
           </form>
           &nbsp
           <form action="<?php echo site_url("users/register_view");?> ">
           		<button class="btn" type="submit">register</button>
           </form>
           
           <?php }?>
             <?php if(isset($msg)){?>
           			<span class="label warning"><?php echo $msg;?></span>
           <?php }?>
        </div>
      </div>
    </div>

<div class="container">

<?php if($items->num_rows() > 0):?>
	<?php foreach($items->result() as $row): ?>
		<span class="label notice"><?php echo anchor($row->affiliate_url,'Go to the shop');?></span><br/>
		<IMG SRC="<?php echo $row->img_url ?>" alt="aaa">
		<br/>
		<p><?php echo $row->description ;?></p>
		<br/>
		
		
		<form action="<?php echo site_url("comments/comments_insert")?>" method="post" onsubmit="return checkInput();">
				<?php echo form_hidden('item_id',$row->item_id);?>
				<?php echo form_hidden('pastUrl',$pastUrl);?>
				<p><textarea id="comment" name="comment" row='3'></textarea><input type="submit" value="submit"/></p>
		</form>
		<hr>
		
		
		<?php
			$sql = "SELECT * FROM comments WHERE item_id = ? order by creat_time desc"; // asc desc
			$comments=$this->db->query($sql, $row->item_id);
		?>
		
		<?php if($comments->num_rows() > 0):?>
			<?php foreach($comments->result() as $row_comments): ?>
				<p><?php echo $row_comments->user_id.':  '.$row_comments->comment ;?></p><br/><br/>
			<?php endforeach;?>
		<?php endif; ?>
		
	<?php endforeach;?>
<?php endif; ?>
</div>
</body>
</html>